#include "changepasswordview.h"
#include "ui_changepasswordview.h"
#include "dboperate.h"

ChangePasswordView::ChangePasswordView(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ChangePasswordView)
{
    ui->setupUi(this);
    setWindowTitle("更改密码");
    successState = false;
}

ChangePasswordView::~ChangePasswordView()
{
    delete ui;
}

void ChangePasswordView::setID(int uuid)
{
    this->uuid = uuid;
}

bool ChangePasswordView::getSuccessState()
{
    return successState;
}

void ChangePasswordView::on_pushButton_clicked()
{
    QString password1 = ui->lineEdit->text();
    QString password2 = ui->lineEdit_2->text();
    if (password1.length() >= 8 && password1.length() <= 12 && password1 == password2)
    {
        DBOperate db;
        bool firstLoginState = db.changeFirstLoginState(uuid, 1);
        if (db.changePassword(uuid, password1) && firstLoginState)
        {
            successState = true;
            close();
        }
    }
}
